
********************************************************************************
* Summary Stats for University Experiments
********************************************************************************

* Paul Musgrave
* musgrave@umass.edu

********************************************************************************
* Importing Data and Stata Cruft
********************************************************************************

clear all

set more off

macro drop _all


global MyDocs "~/Dropbox/0001 Academic Projects/Completed/"

global MyProject "${MyDocs}0171 Parasecurity and Education/Replication"

log using "${MyProject}/LOG Summary University Balance Tables 2025 09 22", replace

use "${MyProject}/University Replication.dta"

global ProjectName "University"

lab def prc2_treat_prclab 2 "PRC Hostile", modify

lab def hispaniclab 0 "Not Hispanic" 1 "Hispanic", modify

lab val hispanic hispaniclab

lab def trustnondifflab 0 "Did not straightline" 1 "Straightlined", modify

lab val trust_nondiff trustnondifflab

lab var trust_nondiff "Straightlining Trust"

set scheme cleanplots

replace white = 0 if hispanic == 1

egen age_cat = cut(age), at(18,30,50,65,88) label
lab var age_cat "Age category"
lab def age_cat 0 "18-29" 1 "30-49" 2 "50-64" 3 "65+", modify

gen experiment = (prc1_treat_level!=.)
lab var experiment "Experiment"
recode experiment (0 = 2)
lab def experimentlab 1 "Experiment 1" 2 "Experiment 2"
lab val experiment experimentlab

lab var gender3 "Gender"

********************************************************************************
* DTables (Summary Tables)
********************************************************************************



dtable i.age_cat i.gender3 i.white i.hispanic i.college i.pid3 						///
	if (fr == 2 & prc2_DV_main != .) | (fr == 1 & prc1_DV_main != .)			///
	, by(experiment) 															///
	title("Demographics By Experiment \label{tab:summary}")						///
	export("${MyProject}/APPENDIX Table A1.tex", replace tableonly) 


********************************************************************************
* Balance Tables 
********************************************************************************

tab pid3, gen(pid3)

lab var pid31 "Democrats"
lab var pid32 "Independents"
lab var pid33 "Republicans"

local balancevars age female white hispanic college pid31 pid32 pid33

***** Experiment 1

*** Hostile

eststo exp1_hostile_0_means: estpost summarize `balancevars' 					///
	if prc1_treat_hostile == 0 & prc1_DV_main_dichot!=.
	
eststo exp1_hostile_1_means: estpost summarize `balancevars' 					///
	if prc1_treat_hostile == 1 & prc1_DV_main_dichot!=.
	
eststo exp1_hostile_diff: estpost ttest `balancevars' if prc1_DV_main_dichot!=. ///
	, by(prc1_treat_hostile) unequal

*** Federal

eststo exp1_federal_1_means: estpost summarize `balancevars' 					///
	if prc1_treat_level == 1  & prc1_DV_main_dichot!=.
	
eststo exp1_federal_2_means: estpost summarize `balancevars' 					///
	if prc1_treat_level ==2  & prc1_DV_main_dichot!=.
	
eststo exp1_federal_diff: estpost ttest `balancevars' if prc1_DV_main_dichot!=. ///
	, by(prc1_treat_level) unequal
	
*** Combined Table
esttab exp1_hostile_0_means exp1_hostile_1_means exp1_hostile_diff 				///
	exp1_federal_1_means exp1_federal_2_means exp1_federal_diff 				///
	using "${MyProject}/APPENDIX Table A4.tex" 			///
	, replace 																	///
	title("Experiment 1 Balance by Treatments \label{tab:exp1balance}")			///
	cell( mean(pattern(1 1 0 1 1 0) fmt(2))     &  b(pattern(0 0 1 0 0 1) fmt(2) star) ///
		sd(pattern(1 1 0 1 1 0) fmt(2) par) & se(pattern(0 0 1 0 0 1) fmt(2) par)) ///
	mtitle("PRC Not Hostile" "PRC Hostile" "Difference (1)-(2)" 				///
		"State" "Federal" "Difference (4)-(5)") 								///
	mgroups("PRC Stance" "Level of Government", pattern(1 0 0 1 0 0) 			///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	label  collabels(none) 														///
	starlevels(* .05 ** .01)
	
***** Experiment 2

*** PRC

eststo exp2_prc_1_means: estpost summarize `balancevars' ///
	if prc2_treat_prc == 1 & prc2_DV_main != .
	
eststo exp2_prc_2_means: estpost summarize `balancevars' ///
	if prc2_treat_prc ==2 & prc2_DV_main != .
	
eststo exp2_prc_diff: estpost ttest `balancevars' if prc2_DV_main != .			///
	, by(prc2_treat_prc) unequal

*** USA

eststo exp2_usa_1_means: estpost summarize `balancevars'	///
	if prc2_treat_usa == 1 &  prc2_DV_main != .
	
eststo exp2_usa_2_means: estpost summarize `balancevars'	///
	if prc2_treat_usa ==2 & prc2_DV_main != .
	
eststo exp2_usa_diff: estpost ttest `balancevars' if prc2_DV_main != .			///
	, by(prc2_treat_usa) unequal
					
					
esttab exp2_prc_1_means exp2_prc_2_means exp2_prc_diff 							///
	exp2_usa_1_means exp2_usa_2_means exp2_usa_diff 							///
	using "${MyProject}/APPENDIX Table A10.tex" 				///
	, replace 																	///
	title("Experiment 2 Balance by Treatments \label{tab:exp2balance}")		///
    cell( mean(pattern(1 1 0) fmt(2))     &  b(pattern(0 0 1) fmt(2) star) 		///
            sd(pattern(1 1 0) fmt(2) par) & se(pattern(0 0 1) fmt(2) par)) 		///
	mtitle("No Stance" "Undermine" "Difference (1)-(2)"							///
	"No Stance" "Undermine" "Difference (4)-(5)"								///
	) ///
	mgroups("PRC Stance" "State Department Stance", pattern(1 0 0 1 0 0) 		///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		label  collabels(none) ///
		starlevels(* .05 ** .01)		

log close
